<html>
<head>
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <link href="${ctx}/wangEditor/3.1.1/wangEditor.min.css" rel="stylesheet">
    <script src="${ctx}/wangEditor/10.0.13/wangEditor.min.js"></script>
    <script src="${ctx}/js/iw.js"></script>
    <link href="${ctx}/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet">
    <script src="${ctx}/bootstrap-switch/js/bootstrap-switch.min.js"></script>
    <script src="${ctx}/layui/lay/modules/laydate.js"></script>
    <style>
        [class*='col-xs-'] {
            margin-bottom: 10px;
        }

        .hide {
            display: none;
        }
    </style>

</head>
<body class="container-fuild" style="padding-top: 8px;">
<form class="form-horizontal" id="form">
    <div class="col-xs-6">
        <div class="form-group">
            <label for="title" class="col-sm-5 control-label pr_no">任务名称</label>
            <div class="col-sm-7">
                <input type="text" style="display:none;" id="taskId" name="taskId"
                       value="<#if task??>${task.taskId!''}</#if>"/>
                <input type="text" class="form-control" id="title" name="title" placeholder="填入应用名称"
                       value="<#if task??>${task.title}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">承诺审核时间(分)</label>
            <div class="col-sm-7">
                <input type="number" class="form-control" id="auditTime" name="auditTime" placeholder="承诺审核时间单位（分钟）"
                       value="<#if task??>${task.auditTime!0}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">任务总量</label>
            <div class="col-sm-7">
                <input type="number" class="form-control" id="total" name="total" placeholder="填入任务总量，填0表示不设总量"
                       value="<#if task??>${task.total}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">每日限量</label>
            <div class="col-sm-7">
                <input type="number" class="form-control" id="amount" name="amount" placeholder="填入每日限量，填0表示不限量"
                       value="<#if task??>${task.amount}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">客户名称</label>
            <div class="col-sm-7">
                <select id="customer" name="customer"
                        style="height: 34px;width: 219px;border-radius: 4px;border-color: #ccc;">
                    <option value="zy">自营</option>
                    <#if customlist?? && ((customlist?size)>0)>
                        <#list customlist as list>
                            <#if task??>
                                <option value="${list.customId}"
                                        <#if list.customId == task.customer>selected</#if> >${list.name}</option>
                            <#else >
                                <option value="${list.customId}">${list.name}</option>
                            </#if>

                        </#list>
                    </#if>
                </select>
            </div>
        </div>
    </div>

    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">客户单价（单位:分）</label>
            <div class="col-sm-7">
                <input type="number" class="form-control" id="bussAmount" name="bussAmount"
                       placeholder="" value="<#if task??>${task.bussAmount!0}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">商务结算单价（单位:分）</label>
            <div class="col-sm-7">
                <input type="number" class="form-control" id="increase" name="increase"
                       placeholder="当价格等于0时不可选择“按比例”奖励模式" value="<#if task??>${task.increase}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">指定设备</label>
            <div class="col-sm-7">
                <select class="form-control" id="channel" name="channel">
                    <option value="" <#if task?? && task.channel == ''>selected</#if>>不限设备</option>
                    <option value="vivo" <#if task?? && task.channel == 'vivo'>selected</#if>>限vivo</option>
                    <option value="oppo" <#if task?? && task.channel == 'oppo'>selected</#if>>限oppo</option>
                    <option value="huawei" <#if task?? && task.channel == 'huawei'>selected</#if>>限huawei</option>
                    <option value="meizu" <#if task?? && task.channel == 'meizu'>selected</#if>>限meizu</option>
                    <option value="test" <#if task?? && task.channel == 'test'>selected</#if>>限测试版本</option>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">任务排序</label>
            <div class="col-sm-7">
                <input type="number" class="form-control" id="sort" name="sort" placeholder="升序排序"
                       value="<#if task??>${task.sort}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">奖励模式</label>
            <div class="col-sm-7">
                <select class="form-control" id="reward" name="reward">
                    <#list rewards as reward>
                        <option value="${reward}"
                                <#if task?? && task.reward == reward>selected</#if>>${reward.title}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">奖励类型</label>
            <div class="col-sm-7">
                <select class="form-control" id="type" name="type">
                    <#list types as type>
                        <option value="${type}" <#if task?? && task.type == type>selected</#if>>${type.title}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">展示奖励</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="label" name="label" placeholder="填入展示奖励，如：奖励0.9元"
                       value="<#if task??>${task.label}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">计算奖励（单位:分）</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="worth" name="worth" placeholder="随机奖励格式n:m，其他填n，单位：分"
                       value="<#if task??>${task.worth}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">视频指南</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="media" name="media" placehotask="填入soso引导指南链接地址"
                       value="<#if task??>${task.media}<#else></#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">前置条件（包名）</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="pkg" name="pkg" placeholder="不填没有前置条件"
                       value="<#if task??>${task.pkg}</#if>">
            </div>
        </div>
    </div>

    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">任务要求</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="mission" name="mission" placeholder="任务要求"
                       value="<#if task??>${task.mission!''}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">关键字</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="keywords" name="keywords" placeholder="keywords"
                       value="<#if task??>${task.keywords!''}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">任务状态</label>
            <div class="col-sm-7">
                <select class="form-control" id="status" name="status">
                    <option value="On" <#if task?? && task.status == 'On'>selected</#if>>上架</option>
                    <option value="Off" <#if task?? && task.status == 'Off'>selected</#if>>下架</option>
                    <option value="Wait" <#if task?? && task.status == 'Wait'>selected</#if>>待上架</option>
                </select>
            </div>
        </div>
    </div>


    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">任务预计用时(分)</label>
            <div class="col-sm-7">
                <input type="number" class="form-control" id="taskTime" name="taskTime" placeholder="预估任务用时单位（分钟）"
                       value="<#if task??>${task.taskTime!0}</#if>">
            </div>
        </div>
    </div>

    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-5 control-label pr_no">达到领取上限后需等待(分钟)</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="waitTime" name="waitTime" placeholder="达到领取上限后需等待"
                       value="<#if task??>${task.waitTime!0}</#if>">
            </div>
        </div>
    </div>

    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-5 control-label pr_no">领取触发隐藏任务的次数</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="waitCount" name="waitCount" placeholder="领取触发隐藏任务的次数"
                       value="<#if task??>${task.waitCount!0}</#if>">
            </div>
        </div>
    </div>

    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">完成后等待时长（单位:小时）</label>
            <div class="col-sm-7">
                <input type="number" class="form-control" id="lessTime" name="lessTime"
                       placeholder="完成后等待时长（单位:小时）" value="<#if task??>${task.lessTime!0}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-5 control-label pr_no">任务图标</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="icon" name="icon" placeholder="填入图标链接地址"
                       value="<#if task??>${task.icon}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-5 control-label pr_no">任务系列</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="taskCategory" name="taskCategory" placeholder="填入任务系列"
                       value="<#if task??>${task.taskCategory!''}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-5 control-label pr_no">任务自动上架时间</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="autoTime" name="autoTime" autocomplete="off" placeholder="不填写标识没有开启" value="<#if task??>${task.autoTime!''}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-5 control-label pr_no">任务自动下架时间</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="autoOffTime" name="autoOffTime" autocomplete="off" placeholder="不填写标识没有设置" value="<#if task??>${task.autoOffTime!''}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-5 control-label pr_no">用户最小金额限制(分)</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="minMoney" name="minMoney" placeholder="0为没有金额限制" value="<#if task??>${task.minMoney!''}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-5 control-label pr_no">任务自动释放时间(分)</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="releaseTime" name="releaseTime" placeholder="任务自动释放时间(分)" value="<#if task??>${task.releaseTime!'30'}<#else>30</#if>">
            </div>
        </div>
    </div>

   <#-- <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-5 control-label pr_no">任务图标</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="icon" name="icon" placeholder="填入图标链接地址"
                       value="<#if task??>${task.icon}</#if>">
            </div>
        </div>
    </div>-->
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label">是否审核</label>
            <div class="col-sm-7">
                <select class="form-control" id="needCheck" name="needCheck">
                    <option value="True" <#if task?? && task.needCheck == 'True'>selected</#if>>需要</option>
                    <option value="False" <#if task?? && task.needCheck == 'False'>selected</#if>>不需要</option>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">是否可重做</label>
            <div class="col-sm-1" style="padding-top: 4px">
                <input name="redo" type="checkbox" <#if task?? && task.redo == 1>checked</#if> data-size="mini"
                       value="1"/>
            </div>
            <label for="size" class="col-sm-5 control-label pr_no">是否首面显示</label>
            <div class="col-sm-1" style="padding-top:4px">
                <input name="showinhp" type="checkbox" <#if task?? && task.showinhp == 1>checked</#if> data-size="mini"
                       value="1"/>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label">可获得奖励倍数</label>
            <div class="col-sm-7">
                <select class="form-control" id="awardMultiple" name="awardMultiple">
                    <option value="1" <#if taskScreenshot?? && taskScreenshot.awardMultiple == 1>selected</#if>>1</option>
                    <option value="2" <#if taskScreenshot?? && taskScreenshot.awardMultiple == 2>selected</#if>>2</option>
                    <option value="3" <#if taskScreenshot?? && taskScreenshot.awardMultiple == 3>selected</#if>>3</option>
                    <option value="4" <#if taskScreenshot?? && taskScreenshot.awardMultiple == 4>selected</#if>>4</option>
                    <option value="5" <#if taskScreenshot?? && taskScreenshot.awardMultiple == 5>selected</#if>>5</option>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label">失败可重做次数</label>
            <div class="col-sm-7">
                <select class="form-control" id="failTimes" name="failTimes">
                    <option value="0" <#if taskScreenshot?? && taskScreenshot.failTimes == 0>selected</#if>>0</option>
                    <option value="1" <#if taskScreenshot?? && taskScreenshot.failTimes == 1>selected</#if>>1</option>
                    <option value="2" <#if taskScreenshot?? && taskScreenshot.failTimes == 2>selected</#if>>2</option>
                    <option value="3" <#if taskScreenshot?? && taskScreenshot.failTimes == 3>selected</#if>>3</option>
                    <option value="4" <#if taskScreenshot?? && taskScreenshot.failTimes == 4>selected</#if>>4</option>
                    <option value="5" <#if taskScreenshot?? && taskScreenshot.failTimes == 5>selected</#if>>5</option>
                    <option value="9999" <#if taskScreenshot?? && taskScreenshot.failTimes == 9999>selected</#if>>不限</option>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label">任务分类</label>
            <div class="col-sm-7">
                <select class="form-control" id="taskCategoryId" name="taskCategoryId">
                    <#list taskClassifys as taskClassify>
                        <option value="${taskClassify.id}" <#if taskScreenshot?? && taskScreenshot.taskCategoryId??&&taskScreenshot.taskCategoryId == taskClassify.id>selected</#if>>${taskClassify.categoryName}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>

    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">任务标签</label>
            <div class="col-sm-1" style="padding-top: 4px;width:200px;">
                <#list taskTags as taskTag>

                    <input name="taskTagId" type="checkbox" <#if tags?? && tags?seq_contains("${taskTag.id}")>checked</#if> data-size="mini"
                           value="${taskTag.id}"/>${taskTag.tagName}

                </#list>
            </div>

        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-5 control-label pr_no">任务简介</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="taskIntroduce" name="taskIntroduce" placeholder="请输入任务简介"
                       value="<#if taskScreenshot??>${taskScreenshot.taskIntroduce}</#if>" maxlength="20">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-5 control-label pr_no">分享简介</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="shareIntroduce" name="shareIntroduce" placeholder="请输入分享简介"
                       value="<#if taskScreenshot??>${taskScreenshot.shareIntroduce!''}</#if>" maxlength="40">
            </div>
        </div>
    </div>
    <div class="col-xs-12">
        <div class="form-group">
            <label for="icon" class="col-sm-5 control-label pr_no">任务备注</label>
            <div class="col-sm-7">
                <textarea name="taskRemarks" id="taskRemarks" placeholder="请输入任务备注" style="width:400px;height:150px;" ><#if taskScreenshot??>${taskScreenshot.taskRemarks}</#if></textarea>
                <#--<input type="text" class="form-control" id="taskRemarks" name="taskRemarks" placeholder="请输入任务备注"
                       value="<#if taskScreenshot??>${taskScreenshot.taskRemarks}</#if>">-->
            </div>
        </div>
    </div>
    <#--<div class="col-xs-6">-->
    <#--<div class="form-group">-->
    <#--<label for="size" class="col-sm-5 control-label pr_no">是否首面显示</label>-->
    <#--<div class="col-sm-7">-->
    <#--<input name="showinhp" type="checkbox" <#if task?? && task.showinhp == 1>checked</#if> data-size="mini" value="1"/>-->
    <#--</div>-->
    <#--</div>-->
    <#--</div>-->
    <div class="col-xs-12" style="padding-left: 60px">
        <button type="button" id="add_btn" class="add_btn">添加步骤（图文）</button>
        <button type="button" id="add_btn2" class="add_btn">添加步骤（输入框：输入）</button>
        <#--<button type="button" id="add_btn3" class="add_btn">添加步骤（评论内容）</button>-->
        <button type="button" id="add_btn4" class="add_btn">添加步骤（图文:非上传图片）</button>
        <input type="text" style="display:none" id="contents" name="contents"/>

    </div>

    <div class="col-xs-12" style="padding: 0 40px 0 60px" id="_contents">

    </div>

</form>
<div class="col-xs-12" style="margin-top: 20px;text-align: center">
    <button style="width: 85px;" class="btn btn-success" id="save_btn">保存</button>
</div>
<style scoped>
    .pr_no {
        padding-right: 0;
    }

    .add_btn {
        height: 34px;
        line-height: 30px;
    }
</style>
<script>

    //时间选择器
    $(document).ready(function () {
        laydate.render({
            elem: '#autoTime'
            ,type: 'time'
        });
        laydate.render({
            elem: '#autoOffTime'
            ,type: 'time'
        });
    });

    var reg = /^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/;

    var es = [];


    var addImage = function (content) {
        var index = Math.round(Math.random() * 10000);
        var container = $("<div>").attr("id", "step" + index);
        var div = $("<div>").attr("id", "editor" + index)
        var imgs = $("<div>").attr("id", "img" + index);
        var del = $("<button>").attr("type", "button").attr("id", "del" + index).text("删除").css({
            "float": "right",
            "margin": "10px 15px"
        }).click(function () {
            if (confirm("是否删除该步骤？")) {
                $("#step" + index).remove();
                for (var i = 0; i < es.length; i++) {
                    if (es[i].index == index) {
                        es.splice(i, 1);
                    }
                }
            }
        });
        var clearfix = $("<div>").css({
            "clear": "both"
        });
        container.append(div).append(imgs).append(del).append(clearfix);
        $("#_contents").append(container);
        var E = window.wangEditor;
        var editor = new E('#editor' + index);
        editor.customConfig.uploadImgShowBase64 = false;
        editor.customConfig.menus=[
            'head',
                'bold',
                'fontSize',
                'fontName',
                'italic',
                'underline',
                'strikeThrough',
                'indent',
                'lineHeight',
                'foreColor',
                'backColor',
                'link',
                'list',
                'justify',
                'quote',
                'emoticon',
                'table',
                'code',
                'splitLine',
                'undo',
                'redo'
            ]
        editor.create();
        $("#_contents").find(".w-e-text-container").css("height", "200px");
        var ctx = uploadify({
            container: '#img' + index
        });
        var step = {
            index: index,
            type: 'image',
            text: editor,
            image: ctx
        };
        es.push(step);

        if (content) {
            if (content.text) {
                editor.txt.html(content.text);
            }
            if (content.image) {
                var images = [];
                images.push(content.image);
                ctx.setContent(images);
            }
            if (content.file) {
                var filess = [];
                filess.push(content.file);
                ctx.setContent(filess);
            }
        }
    };


    var addImageNoUp = function (content) {
        var index = Math.round(Math.random() * 10000);
        var container = $("<div>").attr("id", "step" + index);
        var div = $("<div>").attr("id", "editor" + index)
        var imgs = $("<div>").attr("id", "img" + index);
        var del = $("<button>").attr("type", "button").attr("id", "del" + index).text("删除").css({
            "float": "right",
            "margin": "10px 15px"
        }).click(function () {
            if (confirm("是否删除该步骤？")) {
                $("#step" + index).remove();
                for (var i = 0; i < es.length; i++) {
                    if (es[i].index == index) {
                        es.splice(i, 1);
                    }
                }
            }
        });
        var clearfix = $("<div>").css({
            "clear": "both"
        });
        container.append(div).append(imgs).append(del).append(clearfix);
        $("#_contents").append(container);
        var E = window.wangEditor;
        var editor = new E('#editor' + index);
        editor.customConfig.uploadImgShowBase64 = true;
        editor.create();
        $("#_contents").find(".w-e-text-container").css("height", "200px");
        var ctx = uploadify({
            container: '#img' + index
        });
        var step = {
            index: index,
            type: 'imagenoup',
            text: editor,
            image: ctx
        };
        es.push(step);

        if (content) {
            if (content.text) {
                editor.txt.html(content.text);
            }
            if (content.imagelist) {
                var images = [];
                for (var o = 0; o < content.imagelist.length; o++) {
                    images.push(content.imagelist[o])
                }

                ctx.setContent(images);
            }
            if (content.file) {
                var filess = [];
                filess.push(content.file);
                ctx.setContent(filess);
            }
        }
    };

    var addInput = function (content) {
        var index = Math.round(Math.random() * 10000);
        var container = $("<div>").attr("id", "step" + index);
        var div = $("<div>").attr("id", "editor" + index)
        var input = $("<input>").attr("id", "input" + index).css({
            "width": "300px",
            "margin-top": "8px"
        });
        var del = $("<button>").attr("type", "button").attr("id", "del" + index).text("删除").css({
            "float": "right",
            "margin": "10px 15px"
        }).click(function () {
            if (confirm("是否删除该步骤？")) {
                $("#step" + index).remove();
                for (var i = 0; i < es.length; i++) {
                    if (es[i].index == index) {
                        es.splice(i, 1);
                    }
                }
            }
        });
        var clearfix = $("<div>").css({
            "clear": "both"
        });
        container.append(div).append(input).append(del).append(clearfix);
        $("#_contents").append(container);
        var E = window.wangEditor;
        var editor = new E('#editor' + index);
        editor.customConfig.uploadImgShowBase64 = true;
        editor.create();
        $("#_contents").find(".w-e-text-container").css("height", "160px");
        var step = {
            index: index,
            type: 'input',
            text: editor,
            input: input
        };
        es.push(step);

        if (content) {
            if (content.text) {
                editor.txt.html(content.text);
            }
            if (content.input) {
                input.val(content.input);
            }
        }
    };
    var clock = false;
    var addExcel = function (content) {
        var index = Math.round(Math.random() * 10000);
        var container = $("<div>").attr("id", "step" + index);
        var div = $("<div>").attr("id", index)
        var input = $("<input>").attr("type", "file").attr("id", "file");
        var del = $("<button>").attr("type", "button").attr("id", "del" + index).text("删除").css({
            "float": "right",
            "margin": "10px 15px"
        }).click(function () {
            if (confirm("是否删除该步骤？")) {
                $("#step" + index).remove();
                clock = false;
                for (var i = 0; i < es.length; i++) {
                    if (es[i].index == index) {
                        es.splice(i, 1);
                    }
                }
            }
        });
        var clearfix = $("<div>").css({
            "clear": "both"
        });
        container.append(div).append(input).append(del).append(clearfix);
        $("#_contents").append(container);
        var E = window.wangEditor;
        var editor = new E('#editor' + index);
        editor.customConfig.uploadImgShowBase64 = true;
        editor.create();
        $("#_contents").find(".w-e-text-container").css("height", "80px");
        var step = {
            index: index,
            type: 'comment',
            text: editor,
            input: input
        };
        es.push(step);

        if (content) {
            if (content.text) {
                editor.txt.html(content.text);
            }
            if (content.input) {
                input.val(content.input);
            }
        }
    };

    <#if task??>
    var steps = eval(${task.contents});
    if (steps.length > 0) {
        for (var i in steps) {
            if (steps[i].type == 'input') {
                addInput(steps[i]);
            }
            if (steps[i].type == 'image') {
                addImage(steps[i]);
            }
            if (steps[i].type == 'comment') {
                clock = true;
                addExcel();
            }
            if (steps[i].type == 'imagenoup') {

                addImageNoUp(steps[i]);
            }
        }
    }
    </#if>

    $(function () {

        $("#add_btn").click(function () {
            addImage();
        });

        $("#add_btn2").click(function () {
            addInput();
        });
        $("#add_btn3").click(function () {
            clock = true;
            addExcel();
        });
        $("#add_btn4").click(function () {
            clock = true;
            addImageNoUp();
        });

        $("#save_btn").click(function () {
            if (!$("#title").val()) {
                alert("请填入应用名称！");
                return false;
            }
            if (!$("#icon").val()) {
                alert("请填入应用图标！");
                return false;
            }
            if (!$("#total").val()) {
                alert("请填入任务总量！");
                return false;
            }
            if (!$("#amount").val()) {
                alert("请填入每日限量！");
                return false;
            }
            if (!$("#increase").val()) {
                $("#increase").val(0)
            }
            if (!$("#label").val()) {
                alert("请填入展示奖励！");
                return false;
            }
            if (!$("#taskTime").val()) {
                alert("请填入预计完成时间！");
                return false;
            }
            if (!$("#auditTime").val()) {
                alert("请填入承诺审核时间！");
                return false;
            }
            var taskTime = $('#taskTime').val();
            var auditTime = $('#auditTime').val();
            if ($("#reward").val() == 'Random') {
                if (!/:|：/.test($("#worth").val())) {
                    alert("格式为n：m或者n:m，请填入正确的格式！");
                    return false;
                }
            } else {
                if (!/^[1-9]\d*$/.test($("#worth").val())) {
                    alert("请填入计算奖励需正整数！");
                    return false;
                }
            }
            var mission = $('#mission').val();

            var items = [];

            for (var i = 0; i < es.length; i++) {
                if (es[i].type == 'input') {
                    var item = {
                        type: es[i].type,
                        text: es[i].text.txt.html(),
                        input: es[i].input.val()
                    };
                    items.push(item);
                }
                if (es[i].type == 'image') {
                    var item = {
                        type: es[i].type,
                        text: es[i].text.txt.html(),
                        image: es[i].image.images()[0]
                    };
                    console.log(es[i].image.images()[0]);
                    items.push(item);
                }
                if (es[i].type == 'comment') {
                    var item = {
                        type: es[i].type,
                        text: ''
                    };
                    items.push(item);
                }
                if (es[i].type == 'imagenoup') {
                    var imglist = new Array();
                    for (var o = 0; o < es[i].image.images().length; o++) {
                        imglist.push(es[i].image.images()[o])
                    }

                    var item = {
                        type: es[i].type,
                        text: es[i].text.txt.html(),
                        imagelist: imglist
                    };
                    console.log(es[i].image.images()[0]);
                    items.push(item);
                }
            }


                if($("#autoTime").val()&&!reg.test($("#autoTime").val())){
                    alert("请输入XX:XX:XX格式的任务自动上架时间");
                    return;
                }

            if($("#autoOffTime").val()&&!reg.test($("#autoOffTime").val())){
                alert("请输入XX:XX:XX格式的任务自动下架时间");
                return;
            }



            $("#contents").val(JSON.stringify(items));
            var formData = new window.FormData();
            var keywords = $('#keywords').val();
            var needCheck = $('#needCheck').val();
            var taskId = $('#taskId').val();
            var title = $('#title').val();
            var icon = $('#icon').val();
            var total = $('#total').val();
            var amount = $('#amount').val();
            var customer = $('#customer').val();
            var increase = $('#increase').val();
            var channel = $('#channel').val();
            var sort = $('#sort').val();
            var reward = $('#reward').val();
            var type = $('#type').val();
            var label = $('#label').val();
            var worth = $('#worth').val();
            var media = $('#media').val();
            var pkg = $('#pkg').val();
            var status = $('#status').val();
            var contents = $('#contents').val();
            console.log(contents.length);
            if (contents.length > 15000){
                alert("步骤数据过大!请重新输入");
                return;
            }
            var lessTime = $('#lessTime').val();
            var bussAmount = $('#bussAmount').val();
            var waitCount = $('#waitCount').val();
            var waitTime = $('#waitTime').val();
            var autoTime = $("#autoTime").val();
            var autoOffTime = $("#autoOffTime").val();
            var minMoney = $("#minMoney").val();
            var taskCategory= $("#taskCategory").val();
            var showinhp = 0;
            if ($('[name="showinhp"]').is(":checked")) {
                showinhp = 1;
            }
            var redo = 0;
            if ($('[name="redo"]').is(":checked")) {
                redo = 1;
            }
            var awardMultiple=$("#awardMultiple").val();
            var failTimes=$("#failTimes").val();
            var taskCategoryId=$("#taskCategoryId").val();

            var tagList='';
            $("input[name='taskTagId']:checked").each(function(){
                if(tagList==''){
                    tagList=$(this).val();
                }else{
                    tagList=tagList+','+$(this).val();
                }

            });
            var taskIntroduce=$("#taskIntroduce").val();
            var taskRemarks=$("#taskRemarks").val();
            var shareIntroduce=$("#shareIntroduce").val();

            formData.append("releaseTime", $("#releaseTime").val());
            formData.append("taskCategory", taskCategory);
            formData.append("waitCount", waitCount);
            formData.append("waitTime", waitTime);
            formData.append("lessTime", lessTime);
            formData.append("bussAmount", bussAmount);
            formData.append("keywords", keywords);
            formData.append("mission", mission);
            formData.append("auditTime", auditTime);
            formData.append("taskTime", taskTime);
            formData.append("redo", redo);
            formData.append("needCheck", needCheck);
            formData.append("taskId", taskId);
            formData.append("title", title);
            formData.append("icon", icon);
            formData.append("total", total);
            formData.append("amount", amount);
            formData.append("customer", customer);
            formData.append("increase", increase);
            formData.append("channel", channel);
            formData.append("sort", sort);
            formData.append("reward", reward);
            formData.append("type", type);
            formData.append("label", label);
            formData.append("worth", worth);
            formData.append("media", media);
            formData.append("pkg", pkg);
            formData.append("status", status);
            formData.append("contents", contents);
            formData.append("showinhp", showinhp)
            formData.append("minMoney",minMoney);
            formData.append("autoTime",autoTime);
            formData.append("autoOffTime",autoOffTime);
            formData.append("awardMultiple",awardMultiple);
            formData.append("failTimes",failTimes);
            formData.append("taskCategoryId",taskCategoryId);
            formData.append("taskTagIds",tagList);
            formData.append("taskIntroduce",taskIntroduce);
            formData.append("taskRemarks",taskRemarks);
            formData.append("shareIntroduce",shareIntroduce);

            $.ajax({
                url: "/common/save",
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false, //不设置内容类型
                processData: false, //不处理数据
                success: function (res) {
                    if (res.success) {
                        alert(res.message);
                        window.parent.iw.closeDialog();
                    } else {
                        alert(res.message);
                    }

                }
            });
        });

    });
</script>
</body>
</html>
